package com.wangyk.rabbitmqconsole.aspect;

import com.github.pagehelper.PageHelper;
import com.wangyk.rabbitmqcommon.page.Pagination;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class ByPageAspect
{

    /*
     * 1）第一个*：public，private，protected
     * 2）第一个..：对于任意的包，同级包，子包
     * 3）第二个*：对于所有的方法
     * 4）第二个..：方法中的参数
     */
    @Around("execution(* com.wangyk.rabbitmqconsole.service.impl.*.*ByPage(..))")
    public Object method(ProceedingJoinPoint pjp)
        throws Throwable
    {
        System.out.println("=====Aspect处理=======");

        Object[] args = pjp.getArgs();
        for (Object arg : args)
        {
            System.out.println("参数为:" + arg);
        }
        //给所有的切面加上
        Pagination page= (Pagination)args[0];
        PageHelper.startPage(page.getCurrentPage(),page.getPageNumber());
        long start = System.currentTimeMillis();
        Object object = pjp.proceed();
        System.out.println("Aspect 耗时:" + (System.currentTimeMillis() - start));
        return object;
    }
}
